{include file="common/head" /}

<body>
<div class="x-body" >
    <form class="layui-form">
        <input type="hidden" name="id" value="{$cate.id}">
        <div class="layui-form-item">
            <label for="L_name" class="layui-form-label">
                <span class="x-red">*</span>分类名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_name" name="name" required=""
                     value="{$cate.name}"  autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>图片
            </label>
            <a class="layui-btn" id="image" style="float: left;"><i class="layui-icon">&#xe67c;</i>上传图片</a>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <img src="/images/{$cate.image.url}" id="thumb" alt="" width="400" height="200" style="margin-left: 110px; display: none " >
                <input type="hidden" name="url" value="{$cate.image.url}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_description" class="layui-form-label">
                描述
            </label>
            <div class="layui-input-block">
                <textarea name="description" placeholder="请输入内容" id="L_description" class="layui-textarea">{$cate.description}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="edit" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;




        //监听提交
        form.on('submit(edit)', function(data){
            console.log(data.field);
            $.post('/admin/category_edit',{
                id:data.field.id,
                name:data.field.name,
                url:data.field.url,
                description:data.field.description
            },function (ret) {
                if(ret.code == 1){
                    layer.alert(ret.msg, {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }else{
                    layer.alert(ret.msg, {icon: 5});
                }
            });
            return false;
        });


    });
</script>
<script>

    if($("input[name=url]").val() != undefined){
        $("#thumb").css('display','block');
    }
    layui.use('upload',function(){
        var upload = layui.upload,
            jq = layui.jquery;
        upload.render({
            url: '{:url("admin/upload")}'
            ,elem:'#image'
            ,ext: 'jpg|png|gif'
            ,area: ['200', '200px']
            ,before: function(input){
                loading = layer.load(2, {
                    shade: [0.2,'#000']
                });
            }
            ,done: function(res){
                layer.close(loading);
                $("#thumb").attr('src','/images/'+res.saveName);
                $("input[name=url]").val(res.saveName);
                $("#thumb").css('display','block');
                layer.msg(res.msg, {icon: 1, time: 1000});
            }
        });

    })
</script>
</body>

</html>